﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A2DFramework.NetworkHelpers
{
    public static class IPHelper
    {
        /// <summary>
        /// 获取本地第一个ip地址（ipv4）
        /// </summary>
        /// <returns></returns>
        public static string GetLocalIPv4()
        {
            System.Net.IPHostEntry IpEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());

            for (int i = 0; i != IpEntry.AddressList.Length; i++)
            {
                if (!IpEntry.AddressList[i].IsIPv6LinkLocal)
                {
                    return IpEntry.AddressList[i].ToString();
                }
            }

            return "Unknow Ipv4";
        }
    }
}
